<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
	<meta charset="UTF-8">
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" href="css/iconfont.css">
	<link rel="stylesheet" href="css/global.css">
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<link rel="stylesheet" href="css/bootstrap-theme.min.css">
	<link rel="stylesheet" href="css/swiper.min.css">
	<link rel="stylesheet" href="css/styles.css">
	<link rel="stylesheet" href="css/logo.css" />
	<script src="js/jquery.1.12.4.min.js" charset="UTF-8"></script>
	<script src="js/bootstrap.min.js" charset="UTF-8"></script>
	<script src="js/swiper.min.js" charset="UTF-8"></script>
	<script src="js/global.js" charset="UTF-8"></script>
	<script src="js/jquery.DJMask.2.1.1.js" charset="UTF-8"></script>
	<script src="js/index2.js"></script> 
	<link rel="stylesheet" type="text/css" href="css/center.css">
	<title>新增收货地址</title>
</head>
<body>
	<!--页头-->
	<div id="dingdan"></div>
	<!-- 顶部标题 -->
	<div class="bgf5 clearfix">
		<div class="top-user">
			<div class="inner">
				<a class="logo" href="index.html"><li id="logo"></li></a>
				<div class="title">个人中心</div>
			</div>
		</div>
	</div>
	<div class="content clearfix bgf5"  style="height: 1200px;">
		<section class="user-center inner clearfix">
			<div id="caidan" style="position: absolute;">
            	
           	</div>
			<div class="pull-right">
				<div class="user-content__box clearfix bgf">
					<div class="title">账户信息-收货地址</div>
					<form id="adddatabox" class="user-addr__form form-horizontal" role="form">
						<input type="hidden" id="userid" name="user_id" value=""/>
						<p class="fz18 cr">新增收货地址<span class="c6" style="margin-left: 20px">电话号码、手机号码选填一项，其余均为必填项</span></p>
						<div class="form-group">
							<label for="name" class="col-sm-2 control-label">收货人姓名：</label>
							<div class="col-sm-6">
								<input class="form-control" id="name" name="addressname" placeholder="请输入姓名" type="text">
							</div>
						</div>
						<div class="form-group">
							<label for="details" class="col-sm-2 control-label">收货地址：</label>
							<div class="col-sm-10">
								<div class="addr-linkage">
									<select name="province"></select>
									<select name="city"></select>
									<select name="area"></select>
									<select name="town"></select>
								</div>
								<input class="form-control" name="addressdetailed" id="details" placeholder="建议您如实填写详细收货地址，例如街道名称，门牌号码等信息" maxlength="30" type="text">
							</div>
						</div>
						<div class="form-group">
							<label for="code" class="col-sm-2 control-label">地区编码：</label>
							<div class="col-sm-6">
								<input class="form-control" id="code" name="addresscode" placeholder="请输入邮政编码" type="text">
							</div>
						</div>
						<div class="form-group">
							<label for="mobile" class="col-sm-2 control-label">手机号码：</label>
							<div class="col-sm-6">
								<input class="form-control" id="mobile" name="addressphone" placeholder="请输入手机号码" type="text">
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-6">
								<div class="checkbox">
									<input type="checkbox" id="statusbox" checked="checked"><label for="statusbox">设为默认收货地址</label>
									<input type="hidden" name="status" id="status" value="1" />
								</div>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-6">
								<button id="addaddress" type="submit" class="but">保存</button>
							</div>
						</div>
						<script src="js/jquery.citys.js"></script>
						<script>
							$(document).ready(function(){
								// 添加街道/乡镇
								function townFormat(info){
									$('.addr-linkage select[name="town"]').hide().empty();
									if (info['code'] % 1e4 && info['code'] < 7e6){	//是否为“区”且不是港澳台地区
										var ajaxConfig = {
											url: 'http://passer-by.com/data_location/town/' + info['code'] + '.json',
											scriptCharset:'UTF-8',
											dataType: "json",
											timeout: 4000,
											success: function(data) {
												$('.addr-linkage select[name="town"]').show();
												$('#code').val(info['code']) // 填地区编码
												for (i in data) {
													$('.addr-linkage select[name="town"]').append(
														'<option value="' + data[i] + '">' + data[i] + '</option>'
													);
												};
												$('.addr-linkage select[name="town"]').find('option[value="洪山镇"]').prop("selected", "selected");
											},
										};
										$.ajax(ajaxConfig).fail(function(p1,p2,p3){
											ajaxConfig.url = 'js/data_location/town/' + info['code'] + '.json';
											$.ajax(ajaxConfig)
										});
									}
								};
								$('.addr-linkage').citys({
									// 如果某天这个仓库地址失效了dataUrl请使用本地 2017.10 的数据 'js/data_location/list.json'
									dataUrl: 'http://passer-by.com/data_location/list.json',
									spareUrl: 'js/data_location/list.json',
									dataType: 'json',
									valueType: 'name',
									province: '湖南省',
									city:'株洲市',
									area: '天元区',
									onChange: function(data) {
										townFormat(data)
									},
								},function(api){
									var info = api.getInfo();
									townFormat(info);
								});
							}); 
						</script>
					</form>
					<p class="fz18 cr">已保存的有效地址</p>

					<div class="table-thead addr-thead">
						<div class="tdf1">收货人</div>
						<div class="tdf2">所在地</div>
						<div class="tdf3"><div class="tdt-a_l">详细地址</div></div>
						<div class="tdf1">邮编</div>
						<div class="tdf1">手机</div>
						<div class="tdf1">操作</div>
						<div class="tdf1"></div>
					</div>
					<div id="add-default">
						
					</div>
					<div id="addr-list">
						
						
					</div>
				</div>
			</div>
		</section>
	</div>
	<!-- 右侧菜单 -->
	<div class="right-nav">
		<ul class="r-with-gotop">
			<li class="r-toolbar-item">
				<a href="udai_welcome.html" class="r-item-hd">
					<i class="iconfont icon-user" data-badge="0"></i>
					<div class="r-tip__box"><span class="r-tip-text">用户中心</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="udai_shopcart.html" class="r-item-hd">
					<i class="iconfont icon-cart"></i>
					<div class="r-tip__box"><span class="r-tip-text">购物车</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="Commodity_collection.html" class="r-item-hd">
					<i class="iconfont icon-aixin"></i>
					<div class="r-tip__box"><span class="r-tip-text">我的收藏</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="" class="r-item-hd">
					<i class="iconfont icon-liaotian"></i>
					<div class="r-tip__box"><span class="r-tip-text">联系客服</span></div>
				</a>
			</li>
			<li class="r-toolbar-item">
				<a href="issues.html" class="r-item-hd">
					<i class="iconfont icon-liuyan"></i>
					<div class="r-tip__box"><span class="r-tip-text">留言反馈</span></div>
				</a>
			</li>
			<li class="r-toolbar-item to-top">
				<i class="iconfont icon-top"></i>
				<div class="r-tip__box"><span class="r-tip-text">返回顶部</span></div>
			</li>
		</ul>
		<script>
			$(document).ready(function(){ $('.to-top').toTop({position:false}) });
		</script>
	</div>
	<!-- 底部信息 -->
	<div class="footer" style="position: absolute;top: 1300px;width: 100%;">
		<div class="footer-tags">
			<div class="tags-box inner">
				<div class="tag-div">
					<img src="images/icons/footer_1.gif" alt="厂家直供">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_2.gif" alt="一件代发">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_3.gif" alt="美工活动支持">
				</div>
				<div class="tag-div">
					<img src="images/icons/footer_4.gif" alt="信誉认证">
				</div>
			</div>
		</div>
		<div class="footer-links inner">
			<dl>
				<dt>富城百货</dt>
				<a href="temp_article/udai_article10.html"><dd>企业简介</dd></a>
				<a href="temp_article/udai_article11.html"><dd>加入我们</dd></a>
				<a href="temp_article/udai_article12.html"><dd>隐私说明</dd></a>
			</dl>
			<dl>
				<dt>服务中心</dt>
				<a href="temp_article/udai_article1.html"><dd>售后服务</dd></a>
				<a href="temp_article/udai_article2.html"><dd>配送服务</dd></a>
				<a href="temp_article/udai_article3.html"><dd>用户协议</dd></a>
				<a href="temp_article/udai_article4.html"><dd>常见问题</dd></a>
			</dl>
			<dl>
				<dt>新手上路</dt>
				<a href="temp_article/udai_article5.html"><dd>如何成为代理商</dd></a>
				<a href="temp_article/udai_article6.html"><dd>代销商上架教程</dd></a>
				<a href="temp_article/udai_article7.html"><dd>分销商常见问题</dd></a>
				<a href="temp_article/udai_article8.html"><dd>付款账户</dd></a>
			</dl>
		</div>
		<div class="copy-box clearfix">
			<ul class="copy-links">
				<a href="agent_level.html"><li>网店代销</li></a>
				<a href="class_room.html"><li>U袋学堂</li></a>
				<a href="udai_about.html"><li>联系我们</li></a>
				<a href="temp_article/udai_article10.html"><li>企业简介</li></a>
				<a href="temp_article/udai_article5.html"><li>新手上路</li></a>
			</ul>
			<!-- 版权 -->
			<p class="copyright">
				© 2005-2017 XXX 版权所有，并保留所有权利<br>
				ICP备案证书号：闽ICP备XXX号-2&nbsp;&nbsp;&nbsp;&nbsp;福建省宁德市XXX&nbsp;&nbsp;&nbsp;&nbsp;Tel: XXX&nbsp;&nbsp;&nbsp;&nbsp;E-mail: XXX@qq.com
			</p>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	//顶端导入
	$("#dingdan").load("index_head.html");
	
//	var userid = sessionStorage.getItem("userid");
	
	//获得userid//
	function getUserid(cookieName) {
	    var strCookie = document.cookie;
	    var arrCookie = strCookie.split("; ");
	    for(var i = 0; i < arrCookie.length; i++){
	        var arr = arrCookie[i].split("=");
	        if(cookieName == arr[0]){
	            return arr[1];
	        }
	    }
	    return "";
	}
	
	var userid=getUserid("userid");
	
	$(function(){//第一步都得写这个
		$(document).on("click",".centers_listm_one_in",function(){
		$(this).next(".gjszmdm").slideToggle().siblings("gjszmdm").slideUp()
		});
	})
	/*$(document).ready(function(){ $('.to-top').toTop({position:false}) });*/
	$(document).ready(function(){
		$("#userid").val(userid);
		//显示收货地址(默认)//
		$.ajax({
            type:"GET",
            url:"http://localhost:16111/user/selectmyaddress?status=1&userid="+userid,
            dataType:"json",
            xhrFields:{withCredentials: true},
            success:function(result){
            	$.each(result,function(index,obj){
                	$("#add-default").append("<div class='addr-item'><div class='tdf1'>"+obj['addressname']+"</div><div class='tdf2 tdt-a_l'>"+obj['province']+" "+obj['city']+" "+obj['area']+"</div><div class='tdf3 tdt-a_l'>"+obj['addressdetailed']+"</div><div class='tdf1'>"+obj['addresscode']+"</div><div class='tdf1'>"+obj['addressphone']+"</div><div class='tdf1 order'><a href='#' onclick='addchange("+obj["addressid"]+")'>修改</a><a href='#'>删除</a></div><div class='tdf1'><a href='#' class='default active'>默认地址</a></div><input class='addid' type='hidden' name='addressid' value='"+obj["addressid"]+"'></div>");
           		})
            }	
        });
        //显示收货地址(非默认)//
        $.ajax({
            type:"GET",
            url:"http://localhost:16111/user/selectmyaddress?status=0&userid="+userid,
            dataType:"json",
            xhrFields:{withCredentials: true},
            success:function(result){
            	$.each(result,function(index,obj){
                	$("#addr-list").append("<div class='addr-item'><div class='tdf1'>"+obj['addressname']+"</div><div class='tdf2 tdt-a_l'>"+obj['province']+" "+obj['city']+" "+obj['area']+"</div><div class='tdf3 tdt-a_l'>"+obj['addressdetailed']+"</div><div class='tdf1'>"+obj['addresscode']+"</div><div class='tdf1'>"+obj['addressphone']+"</div><div class='tdf1 order'><a href='#' onclick='addchange("+obj["addressid"]+")'>修改</a><a href='#' onclick='deleltadd(this)'>删除</a></div><div class='tdf1'><a href='#' onclick='changedefault(this)' class='default'>设为默认</a></div><input class='addid' type='hidden' name='addressid' value='"+obj["addressid"]+"'></div>");
           		})
            }	
        });
	})
	memu ();
	function memu ()
	{
	
		var list = "";
		$.ajax({
		    type: "post",//请求方式
		    url: "http://localhost:16111/user/MenuSelect",//上s层的路径
			dataType: "json",
		    data:{},//传值
		    xhrFields:{withCredentials: true},
		    success: function (data)
			{
				var user = eval('(' + JSON.stringify(data.data) + ')');
				
				
				list += '<div class=\"centers_listm_one\">'+
            	'<img src=\"images/zshy.png\"/>'+
                '<a href='+user.memu_url+'><em>'+user.memu_name+'</em></a>'+
            	'</div>';
            	for(var i in user.childMemu)
            	{
            		
            		list +='<div class=\"centers_listm_one_in\">'+
                '<img src=\"images/kouw.png\"/>'+
                '<em>'+user.childMemu[i].memu_name+'</em>'+
                '<b></b>'+
            	'</div>'+
            	'<span class="gjszmdm">';
            		for(var x in user.childMemu[i].childMemu)
            		{
            			if(user.childMemu[i].childMemu[x].memu_name=="宝贝收藏")
            			{
            				list += 
		                '<a href='+user.childMemu[i].childMemu[x].memu_url+'?userid='+sessionStorage.getItem("userid")+' class=\"center_in_self\"  target =\"_blank\"><font>'+user.childMemu[i].childMemu[x].memu_name+'</font></a>';
            			}else if(user.childMemu[i].childMemu[x].memu_name=="我的足迹")
            			{ 	
            				list += 
		                '<a href='+user.childMemu[i].childMemu[x].memu_url+'?userid='+sessionStorage.getItem("userid")+' class=\"center_in_self\" target =\"_blank\"><font>'+user.childMemu[i].childMemu[x].memu_name+'</font></a>';
            			}else 
            			{
            				list += 
		                '<a href='+user.childMemu[i].childMemu[x].memu_url+' class=\"center_in_self\"><font>'+user.childMemu[i].childMemu[x].memu_name+'</font></a>';
            			}
            			
		            	
            		}
            		list+='</span>';
            	} 
            	
            	$("#caidan").html(list);
		   }
		})		
		
	}
	//默认地址复选框//
	$("#statusbox").click(function(){
		var now=$("#status").val();
		if(now==1){
			$("#status").val(0);
		}else{
			$("#status").val(1);
		}
  		
	});
	//新增地址//
	$("#addaddress").click(function(){
		$.ajax({
            type:"post",
            url:"http://localhost:16111/user/addaddress",
            data: $("#adddatabox").serialize(),
            dataType:"json",
            xhrFields:{withCredentials: true},
            success:function(result){
            	if(data){
		          	alert("添加成功");
		          	$(location).attr('href', 'udai_address.html');
		        }else{
		          	alert("添加失败，请在检查网络后重新再试");                         
		        }
            }	
        });
    });
    //设为默认地址//
    function changedefault(obj){
		$.ajax({
            type:"get",
            url:"http://localhost:16111/user/changedefault?addressid="+$(obj).parent().parent().children(".addid").val()+"&user_id="+userid,
            dataType:"json",
            xhrFields:{withCredentials: true},
            success:function(result){
            	if(result){
		          	alert("默认地址修改成功");
		          	$(location).attr('href', 'udai_address.html');
		        }else{
		          	alert("修改失败，请在检查网络后重新再试");                         
		        }
            }	
        });
    }
    //删除地址//
    function deleltadd(obj){
		$.ajax({
          type:"get",
          url:"http://localhost:16111/user/deleltadd?addressid="+$(obj).parent().parent().children(".addid").val()+"&user_id="+userid,
          dataType:"json",
          xhrFields:{withCredentials: true},
          success:function(result){
          	if(result){
		          	alert("地址删除成功");
		          	$(location).attr('href', 'udai_address.html');
		        }else{
		          	alert("删除失败，请在检查网络后重新再试");                         
		        }
            }	
        });
    }
    //跳转修改页面//
    function addchange(url){
		var toUrl = "udai_address_edit.html?addressid=" + url;
        $(location).attr('href', toUrl);
    }
</script>